package com.javafactroy.kunlong.test;


import com.javafactroy.kunlong.FileServer;
import com.javafactroy.kunlong.batch.JobFileRunner;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.batch.core.launch.JobOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.io.IOException;



@SpringBootTest(classes = {FileServer.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ExtendWith(SpringExtension.class)
@Slf4j
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestSpringBatch {

    @Autowired
    JobFileRunner jobFileRunner;

    @Autowired
    JobOperator jobOperator;

    @Test
    public void test001_jobLauncher() throws Exception {

        jobFileRunner.run();
    }


    @Test
    public void test002_jobOperatorNew() throws Exception {

        jobOperator.start("simpleJobNew", "date=" + System.currentTimeMillis());
    }

    @Test
    public void test003_jobOperator0() throws Exception {

        jobOperator.start("simpleJob0", "date=" + System.currentTimeMillis());
    }

    @Test
    public void test004_simpleJob2Table() throws Exception {

        jobOperator.start("simpleJob2Table", "date=" + System.currentTimeMillis());
    }

    @Test
    public void test005_simpleJobReadDbAll2File() throws Exception {

        jobOperator.start("simpleJobReadDb2File", "date=" + System.currentTimeMillis());
    }


    @Test
    public void Test006_exportExls() throws IOException {

//        Date start = DateUtil.parse("2010-01-01 00:00:00", NORM_DATETIME_FORMAT);
//        Date end = DateUtil.parse("2030-01-01 00:00:00", NORM_DATETIME_FORMAT);
////        request.setStartDate(start);
////        request.setEndDate(end);
//        List<ShopOrderDto> orders = memberOrderService.selectShopOrderRequest(request);
//        log.info("Test008_export = {}", CommonUtils.toGsonStr(orders));
//        ExcelExportDto<ShopOrderDto> excelExportDto = new ExcelExportDto<>();
//        excelExportDto.setFileName(StrUtil.format("/home/order{}.xlsx", System.currentTimeMillis()));
//        excelExportDto.setSheetName("订单");
//        excelExportDto.setRecords(orders);
//        excelExportService.exportXls(excelExportDto);
    }

}
